﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HomeCareLibrary.Core.Dtos;
using HomeCareLibrary.DataAccess;

namespace HomeCareLibrary.AppService.Mappers
{
    /// <summary>
    /// Assembler for <see cref="CRC_Task_Details"/> and <see cref="CRC_Task_DetailsDto"/>.
    /// </summary>
    public static partial class CRC_Task_DetailsMapper
    {
        /// <summary>
        /// Invoked when <see cref="ToDTO"/> operation is about to return.
        /// </summary>
        /// <param name="dto"><see cref="CRC_Task_DetailsDto"/> converted from <see cref="CRC_Task_Details"/>.</param>
        static partial void OnDTO(this CRC_Task_Details entity, CRC_Task_DetailsDto dto);

        /// <summary>
        /// Invoked when <see cref="ToEntity"/> operation is about to return.
        /// </summary>
        /// <param name="entity"><see cref="CRC_Task_Details"/> converted from <see cref="CRC_Task_DetailsDto"/>.</param>
        static partial void OnEntity(this CRC_Task_DetailsDto dto, CRC_Task_Details entity);

        /// <summary>
        /// Converts this instance of <see cref="CRC_Task_DetailsDto"/> to an instance of <see cref="CRC_Task_Details"/>.
        /// </summary>
        /// <param name="dto"><see cref="CRC_Task_DetailsDto"/> to convert.</param>
        public static CRC_Task_Details ToEntity(this CRC_Task_DetailsDto dto)
        {
            if (dto == null) return null;

            var entity = new CRC_Task_Details();

            entity.user_id = dto.user_id;
            entity.home_number = dto.home_number;
            entity.task_code = dto.task_code;
            entity.image = dto.image;
            entity.feature_name = dto.feature_name;
            entity.task_description = dto.task_description; 
            entity.timing_months =dto.timing_months;
            entity.cycle_timing = dto.cycle_timing;
            entity.priority = dto.priority;
            entity.benefit_icons = dto.benefit_icons;
            entity.benefit_names = dto.benefit_names;
            entity.benefit_content = dto.benefit_content;
            entity.energy_savings_score = dto.energy_savings_score;
            entity.energy_savings_content = dto.energy_savings_content;
            entity.cost_score = dto.cost_score;
            entity.cost_content =dto.cost_content;    
            entity.type = dto.type;
            entity.start_year = dto.start_year;
            entity.start_month = dto.start_month;             

            dto.OnEntity(entity);

            return entity;
        }

        /// <summary>
        /// Converts this instance of <see cref="CRC_Task_Details"/> to an instance of <see cref="CRC_Task_DetailsDto"/>.
        /// </summary>
        /// <param name="entity"><see cref="CRC_Task_Details"/> to convert.</param>
        public static CRC_Task_DetailsDto ToDTO(this CRC_Task_Details entity)
        {
            if (entity == null) return null;

            var dto = new CRC_Task_DetailsDto();

            dto.user_id = entity.user_id;
            dto.home_number = entity.home_number;
            dto.task_code = entity.task_code;
            dto.image = entity.image;
            dto.feature_name = entity.feature_name;
            dto.task_description = entity.task_description;
            dto.timing_months = entity.timing_months;
            dto.cycle_timing = entity.cycle_timing;
            dto.priority = entity.priority;
            dto.benefit_icons = entity.benefit_icons;
            dto.benefit_names = entity.benefit_names;
            dto.benefit_content = entity.benefit_content;
            dto.energy_savings_score = entity.energy_savings_score;
            dto.energy_savings_content = entity.energy_savings_content;
            dto.cost_score = entity.cost_score;
            dto.cost_content = entity.cost_content;
            dto.type = entity.type;
            dto.start_year = entity.start_year;
            dto.start_month = entity.start_month;

            entity.OnDTO(dto);

            return dto;
        }

        /// <summary>
        /// Converts each instance of <see cref="CRC_Task_DetailsDto"/> to an instance of <see cref="CRC_Task_Details"/>.
        /// </summary>
        /// <param name="dtos"></param>
        /// <returns></returns>
        public static List<CRC_Task_Details> ToEntities(this IEnumerable<CRC_Task_DetailsDto> dtos)
        {
            if (dtos == null) return null;

            return dtos.Select(e => e.ToEntity()).ToList();
        }

        /// <summary>
        /// Converts each instance of <see cref="CRC_Task_Details"/> to an instance of <see cref="CRC_Task_DetailsDto"/>.
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        public static List<CRC_Task_DetailsDto> ToDTOs(this IEnumerable<CRC_Task_Details> entities)
        {
            if (entities == null) return null;

            return entities.Select(e => e.ToDTO()).ToList();
        }
    }
}
